package com.youchuang.action.user;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.ReceiveAddress;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.UserService;

/**
 * 根据地址id修改地址信息
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class UpdateAddressAction extends BaseAction {
	private Logger logger = Logger.getLogger(UpdateAddressAction.class.getSimpleName());
	private ReceiveAddress addr;
	private String id;
	@Resource
	private UserService userService;

	@Action(value = "updateAddress", results = {
			@Result(name = ActionSupport.SUCCESS, type = "redirectAction", params = { "namespace", "/user",
					"actionName", "selectAddress" }) })
	public String execute() throws Exception {

		logger.info("excetion is execute");
		addr.setId(id);
		User user = (User) session.get(Constant.S_USER);
		addr.setUserId(user.getId());

		userService.updateReceiveAddress(addr);

		return Constant.SUCCESS;
	}

	public ReceiveAddress getAddr() {
		return addr;
	}

	public void setAddr(ReceiveAddress addr) {
		this.addr = addr;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
